package cn.manyufun.myf.ui.main.model;

import org.json.JSONException;
import org.json.JSONObject;

import cn.manyufun.myf.api.Api;
import cn.manyufun.myf.api.HostType;
import cn.manyufun.myf.bean.FollowListBean;
import cn.manyufun.myf.common.baserx.RxSchedulers;
import cn.manyufun.myf.common.commonutils.APIUtils;
import cn.manyufun.myf.common.commonutils.DisplayUtil;
import cn.manyufun.myf.ui.main.contract.CollectionListContract;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import rx.Observable;

/**
 * Created by Xiao on 2018-01-31.
 */

public class CollectionListModel implements CollectionListContract.Model {
    @Override
    public Observable<FollowListBean> loadFollowList(int pageIndex, int pageSize) {
        JSONObject root = new JSONObject();
        JSONObject head = APIUtils.getHeadParamter();
        try {
            root.put("Head", head);
            root.put("ImageSize", DisplayUtil.dip2px(92f) + "*" + DisplayUtil.dip2px(127f));
            root.put("PageIndex", pageIndex);
            root.put("PageSize", pageSize);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), root.toString());
        return Api.getDefault(HostType.manyufun).getFollowList(requestBody)
                .compose(RxSchedulers.<FollowListBean>io_main());
    }
}
